package easycloud.ecs.common.domain;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.springframework.data.jpa.domain.AbstractPersistable;

import easycloud.ecs.common.domain.User.Role;

@SuppressWarnings("serial")
@MappedSuperclass
public abstract class AbstractUser extends AbstractPersistable<Integer> {

	@NotNull
	@Size(min = 6, max = 50, message = "email在6到50个字符之间")
	@Column(name = "email", unique = true, nullable = false, length = 50)
	private String email;

	@NotNull
	@Column(name = "password", nullable = false, length = 200)
	private String password;

	@Column(name = "enabled", nullable = false)
	private Boolean enabled;

	@Column(name = "createTime", nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date createTime;

	@Column(name = "lastSigninTime", nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date lastSigninTime;

	@Basic
	@Enumerated(EnumType.STRING)
	@Column(name = "role", nullable = false)
	private Role role;

	@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "user")
	private Set<Folder> folders = new HashSet<Folder>();

	@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "user")
	private Set<Provider> providers = new HashSet<Provider>();

	public Date getCreateTime() {
		return createTime;
	}

	public String getEmail() {
		return email;
	}

	public Boolean getEnabled() {
		return enabled;
	}

	public Set<Folder> getFolders() {
		return folders;
	}

	public Date getLastSigninTime() {
		return lastSigninTime;
	}

	public String getPassword() {
		return password;
	}

	public Set<Provider> getProviders() {
		return providers;
	}

	public Role getRole() {
		return role;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public void setEnabled(Boolean enabled) {
		this.enabled = enabled;
	}

	public void setFolders(Set<Folder> folders) {
		this.folders = folders;
	}

	public void setLastSigninTime(Date lastSigninTime) {
		this.lastSigninTime = lastSigninTime;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setProviders(Set<Provider> providers) {
		this.providers = providers;
	}

	public void setRole(Role role) {
		this.role = role;
	}
}
